<!DOCTYPE html><html><head><title>2018年第二期第一周考试题</title><meta charset='utf-8'><link href='https://dn-maxiang.qbox.me/res-min/themes/marxico.css' rel='stylesheet'><style>.note-content  {font-family: 'Helvetica Neue', Arial, 'Hiragino Sans GB', STHeiti, 'Microsoft YaHei', 'WenQuanYi Micro Hei', SimSun, Song, sans-serif;}


</style></head><body><div id='preview-contents' class='note-content'>
                        
                    



<h3 id="2018年第二期第一周考试题">2018年第二期第一周考试题</h3>

<p></p>

<p>1.</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">if</span> (<span class="hljs-string">'m'</span> <span class="hljs-keyword">in</span> <span class="hljs-built_in">window</span>) {
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span>    <span class="hljs-keyword">var</span> m = m &amp;&amp; <span class="hljs-number">12</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span><span class="hljs-built_in">console</span>.log(m);
</div></code></pre>

<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">let</span> n = <span class="hljs-number">10</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span><span class="hljs-keyword">if</span> (!(<span class="hljs-string">'n'</span> <span class="hljs-keyword">in</span> <span class="hljs-built_in">window</span>)) {
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>    <span class="hljs-keyword">let</span> n = n + <span class="hljs-number">30</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span><span class="hljs-built_in">console</span>.log(n);
</div></code></pre>

<p>2.</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">let</span> n = <span class="hljs-number">10</span>,
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span>    m = <span class="hljs-number">20</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>~<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n, m</span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>    <span class="hljs-keyword">let</span> arg = <span class="hljs-built_in">arguments</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>    arg[<span class="hljs-number">0</span>] = n || <span class="hljs-number">100</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>    arg[<span class="hljs-number">1</span>] = m || <span class="hljs-number">200</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>    <span class="hljs-built_in">console</span>.log(n, m);
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span>}(m);
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span><span class="hljs-built_in">console</span>.log(n, m);
</div></code></pre>

<p>3.</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">let</span> ary = [<span class="hljs-number">12</span>, <span class="hljs-number">23</span>, <span class="hljs-number">34</span>, <span class="hljs-number">45</span>];
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span>(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">ary</span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>    ary.pop();
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>    ary = ary.slice(<span class="hljs-number">0</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>    ary.shift();
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>    <span class="hljs-built_in">console</span>.log(ary);
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>})(ary);
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span><span class="hljs-built_in">console</span>.log(ary);
</div></code></pre>

<p>4.</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span><span class="hljs-keyword">let</span> fn = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>    i += <span class="hljs-number">2</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">m</span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>        i += (++n) + (m--);
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>        <span class="hljs-built_in">console</span>.log(i);
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>    }
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span>};
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span><span class="hljs-keyword">let</span> f = fn(<span class="hljs-number">2</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span>f(<span class="hljs-number">3</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">11.</span>fn(<span class="hljs-number">2</span>)(<span class="hljs-number">3</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span>f(<span class="hljs-number">4</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">13.</span><span class="hljs-built_in">console</span>.log(i);
</div></code></pre>

<p>5.</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">let</span> n = <span class="hljs-number">10</span>,
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span>    obj = {<span class="hljs-attr">n</span>: <span class="hljs-number">20</span>};
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span><span class="hljs-keyword">let</span> fn = obj.fn = (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>    <span class="hljs-keyword">this</span>.n++;
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>    n++;
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">m</span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>        n += <span class="hljs-number">10</span> + (++m);
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span>        <span class="hljs-keyword">this</span>.n += n;
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span>        <span class="hljs-built_in">console</span>.log(n);
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span>    }
</div><div class="hljs-line"><span class="hljs-comment line-number">11.</span>})(obj.n);
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span>fn(<span class="hljs-number">10</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">13.</span>obj.fn(<span class="hljs-number">10</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">14.</span><span class="hljs-built_in">console</span>.log(n, obj.n);
</div></code></pre>

<p>6.</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">let</span> a = {<span class="hljs-attr">n</span>: <span class="hljs-number">4</span>};
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span><span class="hljs-keyword">let</span> b = a;
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>b.x = a = {<span class="hljs-attr">n</span>: <span class="hljs-number">10</span>};
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span><span class="hljs-built_in">console</span>.log(a.x);
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span><span class="hljs-built_in">console</span>.log(b.x);
</div></code></pre>

<p>7.</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">C1</span>(<span class="hljs-params">name</span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span>    <span class="hljs-keyword">if</span> (name) <span class="hljs-keyword">this</span>.name = name;
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">C2</span>(<span class="hljs-params">name</span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>    <span class="hljs-keyword">this</span>.name = name;
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">C3</span>(<span class="hljs-params">name</span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span>    <span class="hljs-keyword">this</span>.name = name || <span class="hljs-string">'join'</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span>C1.prototype.name = <span class="hljs-string">'Tom'</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">11.</span>C2.prototype.name = <span class="hljs-string">'Tom'</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span>C3.prototype.name = <span class="hljs-string">'Tom'</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">13.</span>alert(<span class="hljs-keyword">new</span> C1().name + <span class="hljs-keyword">new</span> C2().name + <span class="hljs-keyword">new</span> C3().name);
</div></code></pre>

<ol start="8"><li rel="8">忽略报错对后面代码的影响</li>
</ol>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">let</span> m = <span class="hljs-number">20</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span><span class="hljs-keyword">let</span> Fn = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n, m</span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>    <span class="hljs-keyword">this</span>.n = n;
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>    <span class="hljs-keyword">this</span>.aa = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>        <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.n + (++m));
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>    }
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>};
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span>Fn.prototype.bb = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span>    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.n + m);
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span>};
</div><div class="hljs-line"><span class="hljs-comment line-number">11.</span><span class="hljs-keyword">let</span> f1 = <span class="hljs-keyword">new</span> Fn(<span class="hljs-number">10</span>, <span class="hljs-number">20</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span>Fn.prototype = {
</div><div class="hljs-line"><span class="hljs-comment line-number">13.</span>    <span class="hljs-attr">cc</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">14.</span>        <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.n + m);
</div><div class="hljs-line"><span class="hljs-comment line-number">15.</span>    }
</div><div class="hljs-line"><span class="hljs-comment line-number">16.</span>};
</div><div class="hljs-line"><span class="hljs-comment line-number">17.</span><span class="hljs-keyword">let</span> f2 = <span class="hljs-keyword">new</span> Fn(<span class="hljs-number">30</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">18.</span><span class="hljs-built_in">console</span>.log(f1.constructor === f2.constructor);
</div><div class="hljs-line"><span class="hljs-comment line-number">19.</span>f1.aa();
</div><div class="hljs-line"><span class="hljs-comment line-number">20.</span>f1.bb();
</div><div class="hljs-line"><span class="hljs-comment line-number">21.</span>f1.cc();
</div><div class="hljs-line"><span class="hljs-comment line-number">22.</span>f2.bb();
</div><div class="hljs-line"><span class="hljs-comment line-number">23.</span>f2.cc();
</div><div class="hljs-line"><span class="hljs-comment line-number">24.</span>f2.__proto__.cc();
</div></code></pre>

<ol start="11"><li rel="11">说出下面代码是否可以依次输出 1~5 的值，不可以请说明原因，以及你的解决方案（至少一种）</li>
</ol>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i &lt;= <span class="hljs-number">5</span>; i++) {
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span>    <span class="hljs-comment">//=&gt;提示:定时器也是异步编程</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>    setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>        <span class="hljs-built_in">console</span>.log(i);
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>    }, <span class="hljs-number">1000</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>}
</div></code></pre>

<ol start="10"><li rel="10">简述你对闭包的理解</li>
</ol></div></body></html>